package aiku.numericalcontroloa.Controller.ClientsController;

import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Model.Dto.ClientsDto;
import aiku.numericalcontroloa.Model.Entity.Chat;
import aiku.numericalcontroloa.Model.Entity.Clients;
import aiku.numericalcontroloa.Model.Entity.Current;
import aiku.numericalcontroloa.Model.Vo.ClientsInfoVo;
import aiku.numericalcontroloa.Model.Vo.ClientsVo;
import aiku.numericalcontroloa.Service.Impl.ClientsServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 马文杰
 * @version 1.0
 */
@RestController
@RequestMapping("/clients")
public class ClientsController {
    @Autowired
    private ClientsServiceImpl clientsService;
    /**
     * 查询所有客户信息，管理员可查询所有，业务员只能查询自己的
     * @description: TODO
     * @param: []
     * @return: java.lang.String
     * @auther: 马文杰
     * @date: 2021/1/26 9:49
     */
    @PostMapping("/selectAllClients")
    public Result selectAllClients(@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("address") String address, @RequestParam("type") String type){
        Page<Clients> pages = new Page<>(page, size);

        ClientsInfoVo clientsVoList =  clientsService.clientList(pages, address, type);
        return Result.success(clientsVoList);
    }

    /**
     * 通过搜索，客户姓名，客户电话，客户公司，客户地址来模糊查询客户信息
     */
    @PostMapping("/selectClientsBySearch")
    public Result selectClientsBySearch(@RequestParam("name") String name){
        ClientsInfoVo clientsVoList =  clientsService.selectClientsBySearch(name);
        return Result.success(clientsVoList);
    }

    /**
    * 通过客户id查询客户信息
     * @description: TODO
     */
    @PostMapping("/selectClientsById")
    public Result selectClientsById(@RequestParam("id") String id){
        ClientsVo clientsVo =  clientsService.selectClientsById(id);
        return Result.success(clientsVo);
    }

    /**
     * 通过客户id查询交流记录
     * @description: TODO
     * @param: []
     * @return: java.lang.String
     * @auther: 马文杰
     * @date: 2021/1/26 9:49
     */
    @PostMapping("/selectChatByClientId")
    public Result selectChatByClientId(@RequestParam("id") String id){
        List<Chat> chatList =  clientsService.selectChatByClientId(id);
        return Result.success(chatList);
    }


    /**
     * 新增客户信息
     * @description: TODO
     * @param: []
     * @return: java.lang.String
     * @auther: 马文杰
     * @date: 2021/1/26 9:49
     */
    @PostMapping("/insertClients")
    public Result insertClients(@RequestBody ClientsVo clientsVo){
        Result ret =  clientsService.insertClients(clientsVo);
        return ret;
    }

    /**
     * 修改客户信息
     * @param clientsVo
     * @return
     */
    @PostMapping("/updateClients")
    public Result updateClients(@RequestBody ClientsVo clientsVo){
        return clientsService.updateClients(clientsVo);
    }

    /**
     * 通过客户id审核客户信息
     * @param type 0:通过 1：待审核 2:不通过
     * @return
     */
    @PostMapping("/auditClients")
    public Result auditClients(@RequestParam("id") String id,@RequestParam("type") Integer type){
        Result ret =  clientsService.auditClients(id,type);
        return ret;
    }

    /**
     * 用户确认新增客户信息
     */
    @PostMapping("/confirmInsertClients")
    public Result confirmInsertClients(@RequestBody ClientsVo clientsVo){
        Result ret =  clientsService.confirmInsertClients(clientsVo);
        return ret;
    }

    /**
     * 通过客户id删除客户信息
     */
    @PostMapping("/deleteClientsById")
    public Result deleteClientsById(@RequestParam("id") String id){
        Result ret =  clientsService.deleteClientsById(id);
        return ret;
    }

    /**
     * 继续添加客户交谈记录
     */
    @PostMapping("/insertChat")
    public Result insertChat(@RequestBody Chat chat){
        Result ret =  clientsService.insertChat(chat);
        return ret;
    }

    /**
     * 把用户派送给业务员，批量派送
     * @description: TODO
     * @param: [ids, userId]    ids:客户id，多个id用逗号隔开，userId:业务员id
     */
    @PostMapping("/dispatchClients")
    public Result dispatchClients(@RequestParam("ids") String ids,@RequestParam("userId") String userId){
        Result ret =  clientsService.dispatchClients(ids,userId);
        return ret;
    }

    /**
     * 业务员年月日，新增客户数量统计，根据类型统计
     * typeOne: 0:成交客户 1：意向客户 2全部 typeTwo：0日，1月
     */
        @PostMapping("/selectClientsCountByType")
    public Result selectClientsCountByType(@RequestParam("typeOne") Integer typeOne,@RequestParam("typeTwo") Integer typeTwo){
        Result ret =  clientsService.selectClientsCountByType(typeOne,typeTwo);
        return ret;
    }

    /**
     * 查询客户，包括已删除的
     * @param clientsDto
     * @return
     */
    @PostMapping("/getClientWithDelete")
    public Result getClientWithDelete(@RequestBody ClientsDto clientsDto){
            return clientsService.getClientWithDelete(clientsDto);
    }

    /**
     * 修改提醒时间
     * @return
     */
    @PostMapping("/updateRemindTime")
    public Result updateRemindTime(@RequestBody ClientsDto clientsDto){
        return clientsService.updateRemindTime(clientsDto);
    }

    /**
     * 查询客户列表
     * 可根据客户姓名，客户公司，电话号码，地址查询
     * 可根据省市区查询
     * 可根据业务员查询
     * @param clientsDto
     * @return
     */
    @PostMapping("/getClientsList")
    public Result getClientsList(@RequestBody ClientsDto clientsDto){
        return clientsService.getClientsList(clientsDto);
    }

    /**
     * 放弃客户，移入公海池
     * @param clientsDto
     * @return
     */
    @PostMapping("/surrenderClients")
    public Result surrenderClients(@RequestBody ClientsDto clientsDto) {
        return clientsService.surrenderClients(clientsDto);
    }

    /**
     * 获取客户缓存信息
     * @param clientsDto
     * @return
     */
    @PostMapping("/getClientsCache")
    public Result getClientsCache(@RequestBody ClientsDto clientsDto){
        return clientsService.getClientsCache(clientsDto);
    }

    /**
     * 审核修改客户信息
     * @param clientsDto
     * @return
     */
    @PostMapping("/updateClientsApply")
    public Result updateClientsApply(@RequestBody ClientsDto clientsDto){
        return clientsService.updateClientsApply(clientsDto);
    }

    /**
     * 认领客户
     * @param clientsDto
     * @return
     */
    @PostMapping("/claimClients")
    public Result claimClients(@RequestBody ClientsDto clientsDto){
        return clientsService.claimClients(clientsDto);
    }

    /**
     *  查询排行榜
     * @param clientsDto
     * @return
     */
    @PostMapping("/rankingList")
    public Result rankingList(@RequestBody ClientsDto clientsDto){
        return clientsService.rankingList(clientsDto);
    }

    /**
     * 获取联系天数
     * @return
     */
    @PostMapping("/getContactDays")
    public Result getContactDays(){
        return clientsService.getContactDays();
    }

    /**
     * 修改联系天数
     * @param current
     * @return
     */
    @PostMapping("/updateContactDays")
    public Result updateContactDays(@RequestBody Current current){
        return clientsService.updateContactDays(current);
    }

}
